import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { LevelLimitDefin } from "../../../../common/defin/LevelLimitDefin";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { TimeButton } from "../../common/button/TimeButton";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { TextBox } from "../../pack/TextBox";
import { MoneyUtil } from "../../common/util/MoneyUtil";
import { SecTimerView } from "../../common/SecTimerView";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SMyCornucopiaInfo } from "../../../../../Message/Public/SMyCornucopiaInfo";
import { ObjTeamCreate } from "../../common/ObjTeamCreate";
import { ClockManager } from "../../../manager/ClockManager";
import { EReward } from "../../../../../Message/Public/EReward";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class CornucopiaMyInfoWindow
    
    export  class CornucopiaMyInfoWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._strTips = Language.getString(40308) + LevelLimitDefin.CornucopiaMinLevel + Language.getString(40309);
            setSize(294, 393);
            titleHeight = 26;
            title = Language.getString(40307);
            return;
        }

        protected /* override */ setWindowCenter(): void
        {
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(14, 35, 266, 74, this);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 15788607);
            loc1.leading = 9;
            this._tfTips = ObjCreate.createTextField(this._strTips, 21, 41, 253, 62, this, loc1);
            this._tfTips.mouseEnabled = false;
            this._tfTips.multiline = true;
            this._tfTips.wordWrap = true;
            this._btnCallFriendBless = new TimeButton(30, true);
            this._btnCallFriendBless.label = Language.getString(40310);
            this._btnCallFriendBless.styleName = "Button";
            ObjCreate.setObjAttri(this._btnCallFriendBless, 130, 84, 100, 22, this);
            this._btnCallFriendBless.addEventListener(flash.events.MouseEvent.CLICK, this.onCallBless);
            if (this.contains(this._btnCallFriendBless)) 
            {
                this.removeChild(this._btnCallFriendBless);
            }
            ObjCreate.createBg(14, 113, 266, 245, this);
            this._bmpBg = new Object /* flash.display.Bitmap */();
            this._bmpBg.x = 13;
            this._bmpBg.y = 113;
            this.addChild(this._bmpBg);
            LoaderManager.instance.load("cornucopiaBg.png", this.onLoadComplete);
            ObjCreate.createTextField(Language.getString(40311), 25, 123, 180, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._tfYesterdayBlessValue = ObjCreate.createTextField(Language.getString(40312) + "0", 22, 300, 125, 20, this);
            this._tfTodayBlessValue = ObjCreate.createTextField(Language.getString(40303) + "0/200", 150, 300, 125, 20, this);
            this._bmpMoney1 = GlobalClass.getBitmap(ImagesConst.Tongqian_bind);
            this._bmpMoney1.x = 26;
            this._bmpMoney1.y = 329;
            this.addChild(this._bmpMoney1);
            this._goldBindTextBox = new TextBox();
            this._goldBindTextBox.textFieldWidth = 60;
            this._goldBindTextBox.textFieldHeight = 19;
            this._goldBindTextBox.bgHeight = 19;
            this._goldBindTextBox.bgWidth = 60;
            this._goldBindTextBox.htmlText = MoneyUtil.getCoinHtml(0);
            ObjCreate.setObjAttri(this._goldBindTextBox, 52, 329, -1, -1, this);
            this._bmpMoney2 = GlobalClass.getBitmap("Tongqian");
            this._bmpMoney2.x = 122;
            this._bmpMoney2.y = 329;
            this.addChild(this._bmpMoney2);
            this._coinTextBox = new TextBox();
            this._coinTextBox.textFieldWidth = 60;
            this._coinTextBox.textFieldHeight = 19;
            this._coinTextBox.bgHeight = 19;
            this._coinTextBox.bgWidth = 60;
            this._coinTextBox.htmlText = MoneyUtil.getCoinHtml(0);
            ObjCreate.setObjAttri(this._coinTextBox, 142, 329, -1, -1, this);
            this._btnGet = ObjCreate.createGButton(Language.getString(40315), 218, 329, 55, 22, this);
            this._btnGet.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnGet);
            this._tfNextConver = new SecTimerView();
            this._tfNextConver.mouseEnabled = false;
            ObjCreate.setObjAttri(this._tfNextConver, 29, 364, 240, 22, this);
            this._tfNextConver.htmlText = "<font color=\'#ff9900\' size=\'14\'><b>" + Language.getString(40314) + "</b></font><font color=\'#F1FFB1\' size=\'14\'><b>00: 00: 00</b></font>";
            this._tfNextConver.setParse("<font color=\'#ff9900\' size=\'14\'><b>" + Language.getString(40314) + "</b></font><font color=\'#F1FFB1\' size=\'14\'><b>hh: mm: ss</b></font>");
            return;
        }

        /* internal  */onLoadComplete(arg1): void
        {
            this._bmpBg.bitmapData = arg1.bitmapData as Object /* flash.display.BitmapData */;
            return;
        }

        /* internal  */onLink(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaCallBless));
            return;
        }

        /* internal  */onCallBless(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaCallBless));
            return;
        }

        /* internal  */onBtnGet(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaGetRewards));
            return;
        }

        public updateInfo(arg1: SMyCornucopiaInfo): void
        {
            var loc1=null;
            ObjTeamCreate.setTextFieldKeyValue(this._tfYesterdayBlessValue, Language.getString(40312), arg1.yesterdayBlessValue.toString());
            ObjTeamCreate.setTextFieldKeyValue(this._tfTodayBlessValue, Language.getString(40313), arg1.todayBlessValue.toString() + "/200");
            this._btnGet.enabled = !arg1.hadGetReward;
            if (arg1.hadGetReward) 
            {
                this._btnGet.enabled = false;
                this._btnGet.label = Language.getString(40381);
            }
            else 
            {
                this._btnGet.enabled = true;
                this._btnGet.label = Language.getString(40315);
            }
            if (arg1.rewards.length > 0) 
            {
                loc1 = arg1.rewards[0];
                this._bmpMoney1.bitmapData = GlobalClass.getBitmapData(this.getImageNameRewardType(loc1.type));
                this._goldBindTextBox.htmlText = MoneyUtil.getCoinHtml(loc1.num);
            }
            if (arg1.rewards.length > 1) 
            {
                loc1 = arg1.rewards[1];
                this._bmpMoney2.visible = true;
                this._coinTextBox.visible = true;
                this._bmpMoney2.bitmapData = GlobalClass.getBitmapData(this.getImageNameRewardType(loc1.type));
                this._coinTextBox.htmlText = MoneyUtil.getCoinHtml(loc1.num);
            }
            else 
            {
                this._bmpMoney2.visible = false;
                this._coinTextBox.visible = false;
            }
            var loc2=ClockManager.instance.nowDate;
            var loc3=loc2.hours * 3600 + loc2.minutes * 60 + loc2.seconds;
            var loc4=24 * 3600 - loc3;
            this._tfNextConver.setLeftTime(loc4);
            return;
        }

        /* internal  */getImageNameRewardType(arg1: int): string
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case EReward._ERewardCoin:
                {
                    return ImagesConst.Tongqian;
                }
                case EReward._ERewardCoinBind:
                {
                    return ImagesConst.Tongqian_bind;
                }
                case EReward._ERewardGoldBind:
                {
                    return ImagesConst.Yuanbao_bind;
                }
            }
            return ImagesConst.Tongqian_bind;
        }

        public static get instance(): CornucopiaMyInfoWindow
        {
            if (!CornucopiaMyInfoWindow._instance) 
            {
                CornucopiaMyInfoWindow._instance = new CornucopiaMyInfoWindow();
            }
            return CornucopiaMyInfoWindow._instance;
        }

        /* internal */ /* var */_tfTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_strTips: string;

        /* internal */ /* var */_tfCallFriendBless: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnCallFriendBless: TimeButton;

        /* internal */ /* var */_bmpBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfYesterdayBlessValue: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTodayBlessValue: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpMoney1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpMoney2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_goldBindTextBox: TextBox;

        /* internal */ /* var */_coinTextBox: TextBox;

        /* internal */ /* var */_btnGet: GButton;

        /* internal */ /* var */_tfNextConver: SecTimerView;

        /* internal */ static /* var */_instance: CornucopiaMyInfoWindow;
    }
